home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Hacking - How to debug protected progs (TXT).zip / OWL-ICE.TXT < prev    next >
Text File  |  1997-03-05  |  32KB  |  698 lines

  1.  
  2.               NO MORE annoying anti SOFT-ICE tricks or
  3.               how to improve SOFT-ICE!
  4.  
  5.  
  6.    intro
  7.  
  8.       today's best EXE protectors contain code to prevent debugging with 
  9.    SOFT-ICE, which is the best debugger among the ones i came across so 
  10.    far. following protectors are known to me to defeat SOFT-ICE:
  11.  
  12.       EEXE (Encrypt Exe found in FZC.EXE)
  13.       HACKSTOP (found in WWPACK.EXE)
  14.       PROTECT! (found in various files)
  15.       GUARDIAN ANGEL (found in some versions of HWINFO.EXE)
  16.       EXELITE (a Polish exe compressor)
  17.       the one written by PREDATOR 666 (found in DCA.EXE v1.4)
  18.       the one used by Martin Malík (found in HWINFO.EXE v3.05 and up)
  19.       DS-CRP by Dark Stalker (hi!)
  20.       SECURE v0.19 by the authors of WWPACK
  21.       ALEC v1.5 (the very best protector :-) by Random
  22.       and a few others i don't remember right now...
  23.  
  24.  
  25.    the problems
  26.  
  27.       SOFT-ICE can be detected/halted/crashed in many ways, here's a short
  28.    list of them (some of them only makes single stepping harder but not
  29.    impossible). i also included a short note on the effects for each version
  30.    of SOFT-ICE:
  31.                  :-( this trick works, 
  32.                  :-) it causes no problems
  33.  
  34.  
  35.       1. by the use of the INT3 interface provided by SOFT-ICE one can 
  36.          check for the presence of SOFT-ICE and then have it execute various
  37.          commands, e.g. HBOOT (see HackStop). the loader part of SOFT-ICE
  38.          also leaves some traces in the low DOS memory, so one can find out
  39.          the entrance values of the INT3 interface even if they were changed
  40.          (see HMVS - a heuristic macro virus scanner - by J. Valky and
  41.          L. Vrtik that uses SECURE v0.19). the Windows versions can also be
  42.          detected by the following code (thanks to Dark Stalker and ACP :-):
  43.  
  44.            mov ebp,"BCHK"
  45.            mov ax,4
  46.            int 3
  47.            cmp ax,4
  48.            jne winice_installed
  49.  
  50.          it seems that BoundsChecker talks to SOFT-ICE via an interface very
  51.          similar to the one between LDR.EXE and SOFT-ICE (although it's
  52.          completely undocumented, as far as i know...)
  53.  
  54.  
  55.          DOS: :-(
  56.          W31: :-( (but the SECURE method is :-)
  57.          W95: not tested yet (probably same as W31)
  58.          WNT: not tested yet (probably same as W31)
  59.  
  60.  
  61.       2. by checking for various devices SOFT-ICE installs ("CVDEBUG",
  62.          "NU-MEGA", "SOFTICE1") and searching the part of the code SOFT-ICE
  63.          leaves in the low DOS memory for some patterns (e.g. "CVDEBUG",
  64.          "NU-MEGA", "SEGMAP", "S-ICE" (the latter coming from the filename),
  65.          and any instruction sequence that's left there) one can detect the
  66.          presence of SOFT-ICE. the Window$ versions provide a VXD entry point
  67.          that can be get by:
  68.  
  69.            mov ax,01684h
  70.            mov bx,0202h ; VXD ID for Winice, check out Ralf Brown's INTLIST
  71.            xor di,di
  72.            mov es,di
  73.            int 2fh
  74.            mov ax,es
  75.            add di,ax
  76.            cmp di,0
  77.            jne winice_is_installed
  78.  
  79.          the Window$ versions can also be detected by calling the "debugger
  80.          install check" function of the Window$ debug kernel (int 42/ax=0041),
  81.          for more details see Ralf Brown's INTLIST.
  82.  
  83.          see HWINFO.EXE and DS-CRP.COM for an extensive application of these
  84.          checks...
  85.  
  86.  
  87.          DOS: :-(
  88.          W31: :-) but the VXD entry point check is :-(
  89.          W95: not tested yet (probably same as W31)
  90.          WNT: not tested yet (probably same as W31)
  91.  
  92.  
  93.       3. by the use of the undocumented ICEBP/INT01 instruction (opcode 0xF1):
  94.          SOFT-ICE gives a short beep before the execution of this instruction
  95.          (it will be reflected back to the V86 mode handler, thus at least
  96.          the intended handler will get it) which can be VERY annoying (and
  97.          make the execution VERY slow), see EEXE for an application of this.
  98.  
  99.          DOS: :-(
  100.          W31: :-)
  101.          W95: not tested yet (probably same as W31)
  102.          WNT: not tested yet (probably same as W31)
  103.  
  104.  
  105.       4. by using the TRAP flag, one can use the single stepping feature to
  106.          call a protection routine (e.g. a decryptor). the problem is, that
  107.          during single stepping SOFT-ICE clears the TRAP flag for the V86 task
  108.          and will neither execute nor step into the INT01 handler of the
  109.          V86 task. many schemes use this trick.
  110.  
  111.          DOS: :-(
  112.          W31: :-(
  113.          W95: not tested yet (probably same as W31)
  114.          WNT: not tested yet (probably same as W31)
  115.  
  116.  
  117.       5. by the use of the debug (DRx) and control (CRx) registers:
  118.          accessing these registers in V86 mode leads to a General Protection
  119.          Fault (INT0D), which SOFT-ICE doesn't handle correctly (it's normally
  120.          used for emulating instructions that access the interrupt flag, the
  121.          debug registers, the control registers, etc.). the protected mode
  122.          handler emulates instructions that access these registers by
  123.          executing them, however it doesn't make note about this for itself,
  124.          i.e. whenever a debug fault is triggered SOFT-ICE will think that
  125.          it must pop up and won't reflect back this exception to the V86 mode
  126.          handler (that's waiting for it in vain). for a working example see
  127.          GUARDIAN ANGEL. furthermore, accessing DR4/5 and CR1 will halt
  128.          SOFT-ICE with a General Protection Violation error message, which is
  129.          of course quite disturbing if it's used many times in the program...
  130.  
  131.          and best of all by accessing CR4 SOFT-ICE simply crashes since
  132.          there's no emulation code for this kind of instructions (there's a
  133.          jump table that tells SOFT-ICE which routine to use to handle these
  134.          instructions and the table ends with CR3...). this method was first
  135.          used by Random in his ALEC.EXE v1.4 :-)
  136.  
  137.          another sad fact is that the emulation in SOFT-ICE is not complete:
  138.          it ALWAYS uses eax no matter what the original instruction was...
  139.  
  140.          e.g. mov dr0,ebx will load dr0 from eax!
  141.               mov ecx,dr0 will load eax from dr0!
  142.  
  143.          i guess it's needless to say how easy it is to detect this behavior...
  144.  
  145.          a sidenote for protection writers: other memory managers that run
  146.          DOS in V86 mode may or may not handle these instructions correctly,
  147.          so the use of this trick is highly discouraged.
  148.  
  149.          DOS: :-(
  150.          W31: :-(
  151.          W95: not tested yet (probably same as W31)
  152.          WNT: not tested yet (probably same as W31)
  153.  
  154.  
  155.       6. by the use of INT08, which is the timer interrupt in real mode DOS,
  156.          and the Double Fault Exception in protected mode. the protected mode
  157.          handler checks whether it was entered from V86 mode or not, and in
  158.          the first case it reflects back this interrupt to the V86 mode
  159.          handler. however, one can't single step into it.
  160.  
  161.          DOS: :-(
  162.          W31: :-)
  163.          W95: not tested yet (probably same as W31)
  164.          WNT: not tested yet (probably same as W31)
  165.  
  166.  
  167.       7. by the use of the INT07 interrupt (this is the Coprocessor Not 
  168.          Available Exception):
  169.          instead of reflecting back this interrupt to the V86 mode handler,
  170.          SOFT-ICE tries to skip the offending coprocessor instruction (it
  171.          checks for some opcodes). it seems the Nu-Mega folks never thought
  172.          it would be called directly... for a real life application get some
  173.          programs written (and protected) by Predator 666.
  174.  
  175.          DOS: :-(
  176.          W31: :-)
  177.          W95: not tested yet (probably same as W31)
  178.          WNT: not tested yet (probably same as W31)
  179.  
  180.  
  181.       8. by the use of the Invalid Opcode Exception (INT06):
  182.          SOFT-ICE tries to emulate some instructions (e.g. LOADALL), and then
  183.          reflects back this exception to the V86 mode handler. however,
  184.          certain opcodes aren't recognized and will give you an error message
  185.          (i.e. execution will be interrupted, if the protection scheme uses
  186.          this trick).
  187.  
  188.          DOS: :-(
  189.          W31: :-(
  190.          W95: not tested yet (probably same as W31)
  191.          WNT: not tested yet (probably same as W31)
  192.  
  193.  
  194.       9. by using direct INTxx calls that are triggered by hardware
  195.          interrupts (e.g. INT08-INT0F, INT70-INT77, if the vectors in the PIC
  196.          are not reprogrammed), one will not be able to single step into the
  197.          interrupt handler. in fact, SOFT-ICE will even execute the next
  198.          instruction and just then stop (if the next instruction is also an
  199.          INTxx call of this type then it will be stepped over as well, and so
  200.          on). so far, i know of no protection scheme that uses this trick,
  201.          but i guess i've just given out a good idea :-).
  202.  
  203.          DOS: :-(
  204.          W31: :-)
  205.          W95: not tested yet (probably same as W31)
  206.          WNT: not tested yet (probably same as W31)
  207.  
  208.  
  209.       A. by reloading IDTR one can change the base and size of the interrupt
  210.          table in real mode as well. however, SOFT-ICE will not emulate this
  211.          instruction (it causes a General Protection Fault in V86 mode) thus
  212.          a protection using LIDT won't run. the only problem is that memory
  213.          managers don't like it very much, so probably we won't see it in a
  214.          real life protection scheme, but one never knows :-).
  215.  
  216.          DOS: :-(
  217.          W31: :-(
  218.          W95: not tested yet (probably same as W31)
  219.          WNT: not tested yet (probably same as W31)
  220.  
  221.  
  222.       B. sometimes one has to call an interrupt directly (GENINT xx), e.g. to
  223.          dump a memory range to disk by using one's memory resident dumper
  224.          (you know what i mean :-) and it's very annoying that SOFT-ICE
  225.          doesn't stop after the interrupt call but executes the program
  226.          being debugged (thus one has to set a breakpoint for a moment at the
  227.          current CS:IP which will result in an unwanted 0xCC byte in the dump,
  228.          if all debug registers are already used).
  229.  
  230.          DOS: :-(
  231.          W31: :-(
  232.          W95: not tested yet (probably same as W31)
  233.          WNT: not tested yet (probably same as W31)
  234.  
  235.       C. in plain DOS INT3 and INT1 are handled by the same routine (which is
  236.          a simple IRET). however, SOFT-ICE changes the INT3 handler of the
  237.          V86 task to another IRET which can be detected by comparing its
  238.          offset to the one of the INT1 handler. see HWINFO.EXE for
  239.          an application
  240.  
  241.          DOS: :-(
  242.          W31: :-)
  243.          W95: not tested yet (probably same as W31)
  244.          WNT: not tested yet (probably same as W31)
  245.  
  246.  
  247.    the solutions
  248.  
  249.       in the following part you'll be presented with some ideas about the
  250.    solution for the problems described above (the file offsets refer to the
  251.    DOS version v2.80, but the ideas should work for other versions, as well.
  252.    the easiest way to apply the patches is using Hacker's View which can
  253.    be found in HIEW531.ZIP).
  254.  
  255.       one general problem is that SOFT-ICE (at least the DOS version) doesn't
  256.    reprogram the hardware interrupt vectors, and this makes life (and the
  257.    interrupt handlers) a bit more complex. the IDT that SOFT-ICE uses has
  258.    entries that point to the following type of code:
  259.  
  260.    push xx
  261.    jmp handler_xx
  262.  
  263.    where xx goes from 0x00 to 0xFF. in v2.80 this code begins at offset
  264.    0x4534. the Win31 version has a very similar code beginning at offset
  265.    0x14167 in v1.52:
  266.  
  267.    push d,[offset_xx]
  268.    jmp handler_xx
  269.  
  270.  
  271.       if you want to understand the patches that follow right below, you
  272.    should study the interrupt handlers (and you should also have a good
  273.    understanding of protected mode). however, some problems cannot be solved
  274.    without understanding the internal flags of SOFT-ICE, and this requires a
  275.    complete disassembly of it, which is a quite hard task i can tell.
  276.  
  277.       anyway, sooner or later it will be done, and then we'll have the
  278.    ultimate debugging/cracking tool in our hands 'cos we'll be able to put in
  279.    some missing functions, e.g. emulation of FlatRealMode, tracing INT1, PIC
  280.    reprogramming, prefetch queue emulation, dumping a memory range to disk,
  281.    etc. until then, enjoy the poor man's patches...
  282.  
  283.       1. some exe protections mentioned earlier are based upon the INT3
  284.          interface of SOFT-ICE (see Ralf Brown's Interrupt List for details).
  285.          this interface is activated when the protected mode INT3 handler of
  286.          SOFT-ICE encounters the magic values in SI and DI. that is, when you
  287.          try to trace through an INT3 call, SOFT-ICE will regain control,
  288.          check for the magic values, and in case they are not found, it will
  289.          reflect back this interrupt to the V86 mode INT3 handler (which it
  290.          was supposed to do anyway). if it finds the magic values, then
  291.          it'll execute the command given in AX (and DS:DX). all of these
  292.          checks happen invisibly to the hacker, so there seems to be no
  293.          solution to defeat this kind of protection (well, there's a slow way
  294.          if you step through every instruction and before the "guilty" INT3
  295.          call you change one or two registers).
  296.  
  297.          however, there's a simple solution: change the magic values SOFT-ICE
  298.          is looking for and this will defeat those protectors based upon the
  299.          INT3 interface. however, it's easier said than done because both
  300.          SOFT-ICE (and WIN-ICE) itself and (W)LDR.EXE use this interface for
  301.          some kind of intra/inter process communication. so every reference
  302.          to the magic values will have to be changed!
  303.  
  304.          to keep the story short here's what i've come up with:
  305.          browsing a few minutes in Hacker's View (another important tool ;-)
  306.          i found the places where those changes had to be done. in order to
  307.          avoid changes where those magic values occur by chance, i wrote an
  308.          MSUB script to change whole instructions (they represent enough
  309.          context). the amount of necessary changes would have forced me to
  310.          use some search&replace utility, anyway. MSUB.EXE can be found in
  311.          MSUB13.ZIP (use an ftp search engine to find it).
  312.  
  313.          the scripts
  314.  
  315.          SICE-VAL.MS: you should specify the old and new magic values in it
  316.                       (note that numbers are decimal!)
  317.  
  318.          SICE2NEW.MS: it will replace the old magic values with the new ones.
  319.                       there are almost 2^32 possible values, only that value
  320.                       is forbidden for SI that equals to the version of
  321.                       SOFT-ICE (for v2.80 it is \128\2, i.e. 0x0280). before
  322.                       SOFT-ICE installs itself, it checks for its presence by
  323.                       using an undocumented function of its INT3 interface by
  324.                       setting AH to 0 or 1. on return SI will be loaded with
  325.                       the version number or left unmodified if it's not
  326.                       installed yet, that's why the version number must differ
  327.                       from the preloaded value of SI.
  328.  
  329.          example usage
  330.  
  331.                   MSUB.EXE SICE2NEW.MS S-ICE.EXE LDR.EXE 
  332.  
  333.          if you're fed up with the shareware delay built into MSUB.EXE,
  334.          here's how you can get rid of it (thanks to a friend of mine ;-)
  335.  
  336.          patch MSUB.EXE v1.3 (113,152 bytes long) as follows:
  337.  
  338.          offset    old new
  339.          00002307: ??  EB
  340.          00002308: ??  03
  341.          0000C0DF: 77  EB
  342.  
  343.  
  344.          the protection that SECURE uses is quite clever 'cos it checks the
  345.          first 16 kBytes for the instruction sequence of
  346.  
  347.          mov si,SI_MAGIC
  348.          mov di,DI_MAGIC
  349.  
  350.          they're encoded as 0BEh,x,y,0BFh,u,v where x,y,u and v are the magic
  351.          values. when it finds 0BEh and 0BFh separated by two bytes from each
  352.          other then it calls INT3 with the supposed magic values (the INT3
  353.          handler is a simple IRET, so no problem should arise if SOFT-ICE is
  354.          not installed). and guess what happens when SECURE finds the traces
  355.          of the loader part of SOFT-ICE in that low memory area...
  356.  
  357.          the only solution that would defeat this kind of protection is to
  358.          change the instructions that load SI and DI before the INT3 calls
  359.          (unfortunately you can't avoid those calls since SOFT-ICE has to
  360.          check for its presence and do other things). for obvious reasons
  361.          (i guess one of the previous versions of this file gave the SECURE
  362.          authors the idea...) i won't give you tips on how to do it, i hope
  363.          you're smart enough to do it yourselves.
  364.  
  365.          the only limit is that you have 6 bytes of space to load both SI and
  366.          DI (i checked that whenever SOFT-ICE uses the INT3 interface it loads
  367.          SI and DI by two consecutive instructions, i.e. you can use the MSUB
  368.          scripts to search for and replace them). another method could be to
  369.          change the HBOOT command to something else (by MSUB of course),
  370.          however other dangerous commands could be still issued...
  371.  
  372.  
  373.          the BoundsChecker interface can be modified in the same way we did
  374.          it with the rest of the INT3 interface: simply modify the value that
  375.          is expected in ebp (but BoundsChecker must be changed as well!).
  376.          look for the string "KHCB" to find the appropriate place.
  377.          the following file offsets are valid for WINICE for Win 3.1 v1.52:
  378.  
  379.          offset    old new
  380.          000130C7: 'K' ?
  381.          000130C8: 'H' ?
  382.          000130C9: 'C' ?
  383.          000130CA: 'B' ?
  384.  
  385.          for WINICE for Win95 v3.0:
  386.  
  387.          offset    old new
  388.          00016FDD: 'K' ?
  389.          00016FDE: 'H' ?
  390.          00016FDF: 'C' ?
  391.          00016FE0: 'B' ?
  392.  
  393.          and for WINICE for Win95 v3.01:
  394.  
  395.          offset    old new
  396.          000243F0: 'K' ?
  397.          000243F1: 'H' ?
  398.          000243F2: 'C' ?
  399.          000243F3: 'B' ?
  400.  
  401.  
  402.       2. the device names can be changed to anything you want, look at the
  403.          beginning of S-ICE.EXE. the real problem is when the protection
  404.          checks for instruction sequences. my only advice is that step through
  405.          the protection and see which part of the code is checked for, then
  406.          try to modify it in S-ICE.EXE (or disassemble, modify and then
  407.          recompile the whole executable, but that's not gonna happen for
  408.          a long time, i guess... :-).
  409.  
  410.          to defeat the int41 check, you have to change both the return value
  411.          of the real and protected mode handlers in WINICE and the value that
  412.          is checked for in KRNL386.EXE, VMM32.VXD, EMM386.EXE, IFSHLP.SYS and 
  413.          NET.EXE. all these changes are necessary otherwise some WINICE
  414.          commands (HWND, TASK) won't work 'cos apparently they rely on some
  415.          Window$ functions which are available only in the debug kernel (and
  416.          during startup these programs/drivers do this int41 check which will
  417.          fail if you don't change the values they're expecting, as well).
  418.  
  419.          there're five places in WINICE that have to be patched (one is a cmp,
  420.          the other four are mov's) and one in each one of the rest. sorry,
  421.          that i don't provide you with detailed offsets, but there're too many
  422.          versions/combinations of both WINICE and Win31/Win95... note, that
  423.          after these changes other programs that want to use debug kernel
  424.          functions will fail :-)
  425.  
  426.          and now let's talk about the VXD entry point check. the ID is stored
  427.          at file offset 0x7821E in WINICE for Win95 v3.01 (to find it in
  428.          other versions as well just look for "SICE   ", and the ID will be
  429.          a few bytes before this text).
  430.  
  431.          so to change the ID just overwrite it there. however, it's not
  432.          enough since some companion programs also test for WINICE by trying
  433.          to get the VXD entry point, i.e. they have to be modified as well.
  434.          they're DLOG.EXE and WLDR.EXE, and search for int2F (opcode: 0xCD
  435.          0x2F) to get to the right place... :-)
  436.  
  437.          anyway, for the versions that come with WINICE for Win95 v3.0,
  438.          the file offsets of the ID are 0x625/6 and 0x68B9/A respectively.
  439.  
  440.  
  441.       3. what we have to do is simply skip the unnecessary parts in the
  442.          handler (the beeps) and simulate the instruction as it would have
  443.          been a direct INT 01 call (opcode: 0xCD 0x01). this way one will not
  444.          only get rid of the beeps but be able to trace into the handler as
  445.          well (and we'll have some space to put some extra code in when we'll
  446.          need it :-).
  447.  
  448.          offset    old new
  449.          00001DD5: 50  EB
  450.          00001DD6: 51  60
  451.  
  452.  
  453.       4. [this part is being worked on]
  454.  
  455.  
  456.       5. there are two possible solutions: we either disable the DRx emulation
  457.          feature of SOFT-ICE (this is quite easy to do) or correct it (this is
  458.          really hard to do). SOFT-ICE emulates each instruction by executing
  459.          a function whose offset is looked up in a table. each function ends
  460.          in the same way: IP of the V86 task is incremented by the appropriate
  461.          amount of bytes. so to disable emulation we'll change the pointers
  462.          in that table to the common end of the functions, this way these
  463.          instructions will essentially be handled as NOPs. i don't know
  464.          whether it's worth to do it or not, since this modification can be
  465.          detected by simply loading one of the debug registers and then
  466.          checking whether it's really been modified or not. a more elegant
  467.          solution would be to reserve a few bytes in the data segment of
  468.          SOFT-ICE for storing the values of these registers and emulate the
  469.          instructions (or at least their loading). anyone out there willing
  470.          to do that?
  471.  
  472.          anyway, here's how to do the patch: the table itself is at file
  473.          offset 0x1F1DD and it has 12 words in it pointing to the
  474.          emulation code of the following instructions:
  475.  
  476.              mov eax,dr0 and mov dr0,eax
  477.              mov eax,dr1 and mov dr1,eax
  478.              mov eax,dr2 and mov dr2,eax
  479.              mov eax,dr3 and mov dr3,eax
  480.              mov eax,dr4 and mov dr4,eax
  481.              mov eax,dr5 and mov dr5,eax
  482.              mov eax,dr6 and mov dr6,eax
  483.              mov eax,dr7 and mov dr7,eax
  484.              mov eax,cr0 and mov cr0,eax
  485.              mov eax,cr1 and mov cr1,eax
  486.              mov eax,cr2 and mov cr2,eax
  487.              mov eax,cr3 and mov cr3,eax
  488.  
  489.          note that there's no offset for emulating CR4...
  490.  
  491.          the offset of the common exit point (i.e. the new value you may want
  492.          to set these pointers to) is 0x175A (this is NOT a file offset...).
  493.  
  494.          these patches still don't cure the problem with CR4. if you decided
  495.          to get rid of the emulation entirely (including CR4) then you can
  496.          do it much easier:
  497.  
  498.          offset    old new
  499.          00002E7E: 03  0A
  500.          00002E7F: 00  01
  501.  
  502.  
  503.       6. i'll give you a general solution in section 8 since INT08 is just a
  504.          a subset of the hardware interrupts which are discussed there.
  505.  
  506.  
  507.       7. this problem can be solved quite easily: we replace the original
  508.          protected mode handler with the one that serves all not_IRQ_related
  509.          interrupts (and whose only task is to reflect them back to the
  510.          V86 mode handler).
  511.  
  512.          offset    old new
  513.          0000455A: B6  14
  514.          0000455B: DF  D6
  515.  
  516.  
  517.       8. what we have to do is to skip the call that prints the error message
  518.          and simply reflect this interrupt back to the V86 mode handler.
  519.          note that your buggy programs won't cause SOFT-ICE to pop up after
  520.          this patch :-) (however, you'll be able to break in and see what
  521.          went wrong).
  522.  
  523.          offset    old new
  524.          00002447: A9  C3
  525.  
  526.  
  527.       9. now we'll make use of the extra space we made in the original INT01
  528.          handler. we have to check whether the interrupt was triggered by a
  529.          hardware IRQ or not. this can be done by the following routine:
  530.  
  531.          push eax          ; save the registers that will be modified
  532.          pushf             ; the order of PUSHs is important!
  533.          mov al,0Bh        ; we'll read in the in-service registers
  534.          out 20h,al        ; master PIC
  535.          out 0A0h,al       ; slave PIC
  536.                            ; there might be needed a short delay here
  537.                            ; however, on my machine it isn't :-)
  538.          in al,20h         ; read INTs being serviced by master PIC
  539.          mov ah,al         ; save for later test
  540.          in al,0A0h        ; read INTs being serviced by slave PIC
  541.          test ax,0FFFFh    ; was it a hardware int?
  542.          jnz original      ; 
  543.          popf              ; restore flags
  544.          pop eax           ; the general handler doesn't expect it
  545.          jmp offset 1B70h  ; this has to be the general handler (this offset
  546.                            ; is valid in v2.80)
  547.          original:
  548.          mov ax,8          ; the first two instructions of the original handler
  549.          popf              ; were push eax, mov ax,8, thus we won't pop eax
  550.          jmp offset 1A77h  ; this has to be the original handler's offset
  551.                            ; plus 5 bytes (the length of push eax, mov ax,8)
  552.  
  553.          and at the beginning of the original handler (offset 0x1A72) we put:
  554.          jmp offset 1DD7h  ; and since it's only 3 bytes long,
  555.                            ; we get 2 spare bytes :-)
  556.  
  557.          the binary patches follow:
  558.  
  559.          offset    old new
  560.          00001A72: 66  E9
  561.          00001A73: 50  62
  562.          00001A74: B8  03
  563.  
  564.          00001DD5: 50  EB
  565.          00001DD6: 51  60
  566.          00001DD7: B9  66
  567.          00001DD8: 03  50
  568.          00001DD9: 00  9C
  569.          00001DDA: B0  B0
  570.          00001DDB: 03  0B
  571.          00001DDC: E6  E6
  572.          00001DDD: 61  20
  573.          00001DDE: 51  E6
  574.          00001DDF: 33  A0
  575.          00001DE0: C9  E4
  576.          00001DE1: E2  20
  577.          00001DE2: FE  8A
  578.          00001DE3: E2  E0
  579.          00001DE4: FE  E4
  580.          00001DE5: E2  A0
  581.          00001DE6: FE  A9
  582.          00001DE7: E2  FF
  583.          00001DE8: FE  FF
  584.          00001DE9: E2  B8
  585.          00001DEA: FE  08
  586.          00001DEB: E2  00
  587.          00001DEC: FE  75
  588.          00001DED: E2  06
  589.          00001DEE: FE  9D
  590.          00001DEF: E2  66
  591.          00001DF0: FE  58
  592.          00001DF1: E2  E9
  593.          00001DF2: FE  7C
  594.          00001DF3: E2  FD
  595.          00001DF4: FE  9D
  596.          00001DF5: E2  E9
  597.          00001DF6: FE  7F
  598.          00001DF7: E2  FC
  599.  
  600.  
  601.       A. to solve this problem we should do a complete disassembly of SOFT-ICE
  602.          since we have to keep track of the base and size of the V86 mode
  603.          interrupt table, and this requires too many changes to be worth to do
  604.          it with simple byte patches.
  605.  
  606.  
  607.       B. a somewhat lame (but it's more than nothing) solution is the
  608.          following: we chain in a P RET command after GENINT by patching
  609.          the jump at the end of the GENINT handler to the beginning of P RET.
  610.          after executing GENINT we'll land at the IRET of our handler and
  611.          a further P or T will take us back to the original instruction we
  612.          were at. i said it was somewhat lame... but it works :-)
  613.  
  614.          offset    old new
  615.          000118BF: BC  00
  616.          000118C0: E0  C7
  617.  
  618.  
  619.       C. before executing anything call up SOFT-ICE and change the offset of
  620.          the V86 mode INT3 handler to the one of the INT1 handler.
  621.  
  622.  
  623.       D. !!! SURPRISE !!!
  624.  
  625.          while you're in WINICE for Win95 v3.0 or 3.01 type in the following
  626.          command: "ver ice" and see what you get... however, note that due
  627.          to a bug (or feature?) you can use only once this command during
  628.          a session, you have to restart WINICE to be able to get the
  629.          message again.
  630.  
  631.          and while we're at undocumented features, try out "ver ?" as well.
  632.          in the next release, i'll try to write a detailed description
  633.          of the new commands (not that if it were that hard to find out...)
  634.  
  635.  
  636.    unsolved mysteries :-)
  637.  
  638.       1. even the Nu-Mega docs tell about a problem when SOFT-ICE for DOS is
  639.          loaded from the command line: if HIMEM.SYS is installed the machine
  640.          simply reboots. i tracked down the problem and found out that the
  641.          processor resets itself because of a triple fault. it happens so:
  642.  
  643.          after preparing the IDT and GDT (and loading IDTR and GDTR), paging
  644.          will be enabled in CR0, and then DS and ES will be loaded a
  645.          descriptor offset of 8. however, both this descriptor and the IDT
  646.          seem to be invalid, and this leads to a triple fault. unfortunately,
  647.          i couldn't find out what goes wrong during the setup of IDT and GDT,
  648.          perhaps someone else out there will do the dirty job :-)... and maybe
  649.          Nu-Mega will award you with a free, legal version :-)).
  650.  
  651.  
  652.       2. on a Cyrix 486DLC-40 system (both with and without a coproc) SOFT-ICE
  653.          gets a Page Fault and halts if the processor is running at 40 MHz,
  654.          but works fine at 33 MHz. the Page Fault seems to happen while the
  655.          code window is being put out (i.e. during the execution of the wc
  656.          command). this is nonsense! so far, no solution... and yes, it's
  657.          another dirty job...
  658.  
  659.  
  660.    P.S. for everyone
  661.  
  662.          perhaps there's someone out there who didn't know it so far...
  663.          WINICE can be used without Window$ (and you'll be able to debug
  664.          programs that use some DOS extender, if it can make use of DPMI, but
  665.          that's the case with the most popular ones, e.g. DOS4GW or PMODE/W)!
  666.          the trick is that you have to make a 'crippled' version of Window$,
  667.          i.e. make Window$ start without its GUI. a complete description of
  668.          this can be found at the following URL:
  669.  
  670.                 http://www.fys.ruu.nl/~faber/Windows_No_GUI
  671.  
  672.          after creating this GUI-less Window$ all you have to do is to start
  673.          WINICE (beware, your normal Window$ shouldn't be on your PATH!) and
  674.          voila, you'll be in a DOS session (i hope that you could find it out
  675.          yourself that you had to start COMMAND.COM as your KRNL386.EXE...)
  676.          with WINICE being able to pop up whenever you need it (of course, for
  677.          native Window$ programs you'll need a full Window$).
  678.  
  679.          and if we're at Window$ here's another trick: if you don't want to
  680.          see the logo being shown every time you start Window$, either start
  681.          WIN.COM with a command line paramater of ':' i.e.
  682.  
  683.                 WIN.COM :
  684.  
  685.          or (as the above method doesn't work with our GUIless version since
  686.          WINICE doesn't seem to pass any parameters or you are too lazy to
  687.          type in every time 2 more characters :-) look for the string 'LOGO'
  688.          in WIN.COM and change it to something else (it's enough to change
  689.          only one bit). note, that the WIN.COM of Window$ for Workgroups
  690.          doesn't like this patch...
  691.  
  692.  
  693.    P.S. for protection writers
  694.  
  695.          i know that some of the above modifications can be defeated (i could
  696.          do it myself) however i won't make your life easier... i hope you
  697.          understand why :-)
  698.